package cn.xuchunh.campusbbs.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;

import cn.xuchunh.campusbbs.bean.Reply;
import cn.xuchunh.campusbbs.ui.fragments.TopicReplyDetailFragment;

/**
 * Created by XuChunH on 2015/10/30.
 */
public class TopicReplyPagerAdapter extends FragmentStatePagerAdapter {

    private List<Reply> replyList;

    public TopicReplyPagerAdapter(FragmentManager fm) {
        this(fm, new ArrayList<Reply>());
    }

    public TopicReplyPagerAdapter(FragmentManager fm, List<Reply> list) {
        super(fm);
        replyList = new ArrayList<>();
        replyList.addAll(list);
    }


    @Override
    public Fragment getItem(int position) {
        return TopicReplyDetailFragment.getInstance(position, replyList.get(position));
    }

    @Override
    public int getCount() {
        return replyList.size();
    }

    public void addReply(Reply reply) {
        replyList.add(reply);
        notifyDataSetChanged();
    }

    public void addReplyList(List<Reply> list) {
        replyList.addAll(list);
        notifyDataSetChanged();
    }

}
